*****************************************
*Total Factory Productivity (TFP) Estimation
*****************************************
*****************************************
* When cleaning the data for TFP estimation,
* I followed the instructions by Thomas Winsberry, available at
* https://www.thomaswinberry.com/teaching/phd_lectures/homework1.pdf
*****************************************

use firm_tfp.dta, clear

xtset gvkey fyear
gen ln_s = log(sale_deflate)   //real sales
gen ln_e = log(emp)            //employment
gen ln_m=log(mat_deflate)      //intermediate materials, calculated from xlr. If xlr is missing or below zero, impute (sale-oibdp-expense)
gen ln_a=log(age+1)              // age of firms
gen ln_i = log(invest2_deflate)   //lagged deflated investments
gen ln_c2=log(capital2_deflate) //lagged capital stock constructed according to Winsberry
gen va = sale_deflate - mat_deflate.  //value added
gen ln_v = ln(va)    

acfest ln_s, state(ln_c2 ln_a) proxy(ln_i) intmat(ln_m) free(ln_e) i(gvkey)  t(fyear) nbs(100)  invest
predict omega_hat, omega

